import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 公司
class HttpCompanyService {
  /// 创建公司
  static Future<Response> createCompanies(
      String name, String businessType, String industryType) {
    return BaseConfig.httpBase.postJson('/api/companies', {
      'name': name,
      'business_type': businessType,
      'industry_type': industryType,
    });
  }

  /// 显示公司
  static Future<Response> showCompanies(String company) {
    return BaseConfig.httpBase.get('/api/companies/$company', {});
  }

  /// 所有公司
  static Future<Response> companyList() {
    return BaseConfig.httpBase.get('/api/companies', {});
  }

  /// 更新联系人
  static Future<Response> updateCompanies(
    int companyId, {
    String name,
    String business_type,
    String industry_type,
    String uen,
    String phone_number,
    String email,
    String website,
    String logo,
    String country_code,
    String country,
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_line_2,
    String address_unit,
    String delivery_address_country,
    String delivery_address_city,
    String delivery_address_postal_code,
    String delivery_address_line_1,
    String delivery_address_line_2,
    String delivery_address_unit,
    String financial_year_start_at,
    String financial_year_end_at,
    int financial_year_period,
    int enable_gst,
    String gst_number,
    String gst_effective_date,
  }) {
    return BaseConfig.httpBase.putJson('/api/companies/$companyId', {
      "name": name,
      "business_type": business_type,
      "industry_type": industry_type,
      "uen": uen,
      "phone_number": phone_number,
      "email": email,
      "website": website,
      "country": country,
      "logo": logo,
      "country_code": country_code,
      "address_country": address_country,
      "address_city": address_city,
      "address_postal_code": address_postal_code,
      "address_line_1": address_line_1,
      "address_line_2": address_line_2,
      "address_unit": address_unit,
      "delivery_address_country": delivery_address_country,
      "delivery_address_city": delivery_address_city,
      "delivery_address_postal_code": delivery_address_postal_code,
      "delivery_address_line_1": delivery_address_line_1,
      "delivery_address_line_2": delivery_address_line_2,
      "delivery_address_unit": delivery_address_unit,
      "financial_year_start_at": financial_year_start_at,
      "financial_year_end_at": financial_year_end_at,
      "financial_year_period": financial_year_period,
      "enable_gst": enable_gst,
      "gst_number": gst_number,
      "gst_effective_date": gst_effective_date
    });
  }

  /// 获取公司设置
  static Future<Response> getCompanySetting() {
    return BaseConfig.httpBase.get('/api/companies/setting', {});
  }

  static Future<Response> closeFinancialYear() {
    return BaseConfig.httpBase
        .postJson('/api/companies/close_financial_year', {});
  }

  static Future<Response> getFinancialYears() {
    return BaseConfig.httpBase.get('/api/company/financial_year', {});
  }

  static Future<Response> selectFinancialYear(int id) {
    return BaseConfig.httpBase.putJson('/api/company/financial_year/$id', {});
  }
}
